#pragma once

#include "unit.h"
#include "D3DGraphics.h"
#include "keyboard.h"
#include "mouse.h"
#include <list>
#include <ctime>

class world_t
{
private:
	std::list<ai_unit_t> ai_units; /* A linked list of artificial intelligence units */
	main_unit_t main_unit; /* The unit which we can move with arrow keys */

	rectangle_screen_t world_rect; // The entire world
	rectangle_screen_t view_rect; // The camera (what we view on the screen)
	rectangle_screen_t main_unit_box; // What the main unit can move inside of without moving the screen

	void set_view(); // Calculate where the camera should be in the world

	/* Function ensuring that a rectangle is inside the world */
	void clamp_rectangle_to_world( rectangle_screen_t &rect );

	// process_units()
	
	void resolve_collisions();

	/* Retrieve keyboard input from keyboard object and process it */
	void process_keyboard_input( KeyboardClient &kbd );

	/* Here we actually numerically integrate a time step, delta_time. For example, to calculate the new position of an object one calculates position = velocity*delta_time */
	void elapse_time(double delta_time);

	/* Draw everything to the graphics object */
	void construct_screen_graphics( D3DGraphics &gfx );

	/* Draw world background to graphics object. Used by the more general drawing function above. */
	void draw_background( D3DGraphics &gfx );

	/* Time related variables */
	double delta_time; // The time step of the world. Might have to make several such steps for each frame (or less, in which case we just step that smaller amount).
 	double accumulator; // How much time we should step in total.
	time_t previous_time; // Used to calculate how much time has passed between frames.
public:
	world_t();
	//void process_mouse_input(unsigned char);
	
	void process_frame( D3DGraphics &gfx, KeyboardClient &kbd );
	// get_screen_surface();
};